<template>
  <div class="wrap">
    <header>
      <div class="headertop">
        <div class="header-img">
          <v-back></v-back>
        </div>
        <h1>
          <v-title></v-title>
        </h1>
        <div class="topradius">
          <i class="iconfont icon-xiaochengxu-gengduo"></i>
          <i class="topborder"></i>
          <i class="iconfont icon-xiaochengxu-guanbi"></i>
        </div>
      </div>
      <nav class="head-nav">
        <ul>
          <li><a href="">商品</a></li>
          <li><a href="">评价</a></li>
          <li><a href="">详情</a></li>
          <li><a href="">推荐</a></li>
        </ul>
      </nav>
    </header>
    <div class="content" v-for="item in goodsinfo" :key="item.id">
      <div class="product-img">
        <img :src="item.img" alt="" />
        <p class="iconfont icon-fenxiang"></p>
        <p>8/8</p>
      </div>
      <div class="product-inf">
        <div class="infor-top">
          <p>
            <i>￥</i>{{ item.price }}<b>￥{{ item.market_price }}</b>
          </p>
          <p class="iconfont icon-shoucang">收藏</p>
        </div>
        <div class="infor-content">
          <p>{{ item.goodsname }}</p>
          <p v-html="item.description"></p>
          <p>11.11限时299元起</p>
          <p>
            此商品于2020-11-11,00点结束闪购特卖，品牌美妆闪购专场<i>查看 ></i>
          </p>
        </div>
      </div>
      <div class="inf-bottom">
        <div class="bottom-con">
          <p>领券</p>
          <p><i>300</i><i>50</i><i>10</i></p>
        </div>
        <div class="bottom-con bottom-con2">
          <p>分期</p>
          <p>可选3/6/12分期<b>></b></p>
        </div>
      </div>
    </div>
    <div class="foot">
      <van-goods-action>
        <van-goods-action-icon icon="chat-o" text="客服" />
        <van-goods-action-icon icon="shop-o" text="店铺" />
        <van-goods-action-icon icon="cart-o" text="购物车" />
        <van-goods-action-button
          type="warning"
          text="加入购物车"
          @click="addcart"
        />
        <van-goods-action-button type="danger" text="立即购买" />
      </van-goods-action>
    </div>
  </div>
</template>

<script>
import { cartadd, detail } from "../request/api";
export default {
  data() {
    return {
      goodsinfo: [],
    };
  },
  mounted() {
    // 获取当前商品信息
    detail({
      id: this.$route.params.id,
    }).then((res) => {
      // console.log(res, "成功");
      if (res.data.code == 200) {
        this.goodsinfo = res.data.list;
      }
    });
  },
  methods: {
    addcart() {
      if (sessionStorage.getItem("islogin")) {
        cartadd({
          uid: JSON.parse(sessionStorage.getItem("islogin")).uid,
          goodsid: this.goodsinfo[0].id,
          num: 1,
        }).then((res) => {
          // console.log(res);
          if (res.data.code == 200) {
            this.$router.push("/shopping");
          }
        });
      } else {
        this.$router.push("/login");
      }
    },
  },
};
</script>

<style scoped>
.headertop {
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}
.head-nav {
  background-image: linear-gradient(180deg, #ff6040 0%, #ff8a80 100%);
  box-shadow: 0 2px 6px 0 rgba(255, 149, 128, 0.5);
  padding: 0 0.2rem;
}
.head-nav ul {
  height: 0.72rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.head-nav li {
  align-self: stretch;
  display: flex;
}
.head-nav ul a {
  position: relative;
  color: #fff;
  font-size: 0.32rem;
  align-self: stretch;
  padding-top: 0.2rem;
}
.head-nav ul a:hover {
  font-weight: bold;
}
.head-nav ul li:hover a:after {
  content: "";
  display: block;
  width: 0.4rem;
  height: 0.06rem;
  background: #fff;
  position: absolute;
  left: 50%;
  margin-left: -0.2rem;
  bottom: 0;
}
.product-img {
  position: relative;
}
.product-img img {
  width: 7.5rem;
  height: 7.5rem;
}
.product-img p::before {
  display: block;
  width: 0.48rem;
  height: 0.48rem;
  font-size: 0.4rem;
  text-align: center;
  line-height: 0.48rem;
  color: #fff;
  background: rgba(51, 51, 51, 0.8);
  border-radius: 50%;
  position: absolute;
  right: 0.2rem;
  top: 0.2rem;
}
.product-img p:last-child {
  font-size: 0.28rem;
  height: 0.36rem;
  width: 0.8rem;
  text-align: center;
  line-height: 0.36rem;
  background: rgba(51, 51, 51, 0.8);
  border-radius: 0.18rem;
  position: absolute;
  right: 0.2rem;
  bottom: 0.2rem;
  color: #fff;
}
.product-inf {
  padding: 0 0.2rem;
}
.infor-top p:first-child {
  font-size: 0.4rem;
  color: #ff6040;
  line-height: 0.32rem;
}
.infor-top p:first-child e {
  font-size: 0.24rem;
}
.infor-top p:first-child b {
  font-size: 0.24rem;
  color: #999999;
  line-height: 0.24rem;
  text-decoration: line-through;
}
.infor-top {
  display: flex;
  justify-content: space-between;
  margin-top: 0.3rem;
}
.icon-shoucang:before {
  display: block;
  font-size: 0.2rem;
}
.infor-top p:last-child {
  font-size: 0.2rem;
  color: #ff6040;
  letter-spacing: 0;
  text-align: center;
  line-height: 0.2rem;
}
.infor-content p:first-child {
  font-size: 0.32rem;
  color: #333333;
  line-height: 0.32rem;
  margin: 0.22rem 0 0.11rem;
}
.infor-content p:nth-child(2) >>> img {
  font-size: 0.28rem;
  color: #999999;
  line-height: 0.28rem;
  width: 100%;
}
.infor-content p:nth-child(3) {
  display: inline-block;
  background: #ff8066;
  font-size: 0.2rem;
  color: #ffffff;
  line-height: 0.2rem;
  padding: 0.06rem;
  margin: 0.26rem 0 0.18rem;
}
.infor-content p:nth-child(4) {
  background: #f2f2f2;
  font-size: 0.2rem;
  color: #999999;
  text-align: justify;
  line-height: 0.28rem;
  padding: 0.06rem 0.1rem;
}
.infor-content p:nth-child(4) i {
  color: #ff6040;
  float: right;
}

.inf-bottom {
  border-top: 20px solid #f2f2f2;
  margin-top: 0.16rem;
  min-height: 70vh;
}
.bottom-con {
  padding: 0.44rem 0 0 0.2rem;
  display: flex;
  justify-content: space-between;
}
.bottom-con p:first-child {
  font-size: 0.24rem;
  color: #333333;
  line-height: 0.32rem;
}
.bottom-con p:last-child {
  width: 6.45rem;
  padding-bottom: 0.2rem;
  border-bottom: 2px solid #cccccc;
}
.bottom-con p:last-child i {
  display: inline-block;
  font-size: 0.2rem;
  color: #663014;
  line-height: 0.24rem;
  background-image: url(../assets/Image/m-index/full.png);
  width: 0.66rem;
  height: 0.32rem;
  background-size: 0.66rem 0.32rem;
  text-align: center;
  line-height: 0.32rem;
  margin-right: 0.2rem;
}
.bottom-con2 p:last-child {
  border-bottom: 0px;
  font-size: 0.24rem;
  color: #666666;
  line-height: 0.24rem;
  line-height: 0.32rem;
  padding-right: 0.2rem;
  box-sizing: border-box;
}
.bottom-con2 p:last-child b {
  float: right;
}
</style>
